import host from './host'
import {appId} from '../const/common'
console.log(appId)
// {errcode: "1203", msg: "未登录", data: null, success: false}
const app = getApp()
const {host:url1} = host

export const fetch = (url, data={}, method='POST') => {

  const fixUrl = url1 + url;
  data.appId = appId;
  // let memberEncode = wx.getStorageSync('memberEncode')
  return new Promise((resolve, reject) => {
    wx.request({
      url:fixUrl,
      data,
      header:{
        'content-type': 'application/x-www-form-urlencoded', //修改此处即可
        'mpsessid': wx.getStorageSync('memberEncode')
      },
      method,
      fail(res){
        // console.log('fail', res)
        wx.showToast({
          title: '获取数据失败！',
          icon:'none'
        })
        reject(res.data)
      },
      success(res = {}){
        // console.log('success', res)
        resolve(res.data)
      }
    })

  })


}